(function (){
    var tab = new fz.Scroll('.ui-tab', {
        role: 'tab',//连接tab这个特效插件
        autoplay: false,//内容不滚动
        interval: 1000//滚动的时间间隔
    });
//输入内容不能为空也不能有空格的函数
    function funIf(x1,y1){
        $(x1).on("blur",function(){
            var yourInfo1=/\s/;/*含空格*/
            if($(x1).val().length>0){
                if(yourInfo1.test($(x1).val())){
                    $(y1).css({color:"red"})
                }else{
                    $(y1).css({color:"green"})
                    //console.log($(x1).val().length)
                }
            }else{
                $(y1).css({color:"red"})
            }
        })
    }
    //车次
    funIf(".iptCheCi1TM",".lblCheCi1TM");
    funIf(".iptCheCi2TM",".lblCheCi2TM");
    //乘客姓名
    funIf(".iptPassengerName1TM",".lblPassengerName1TM");
    funIf(".iptPassengerName2TM",".lblPassengerName2TM");
    //订单号��
    funIf(".iptNum1TM",".lblNum1TM");
    funIf(".iptNum2TM",".lblNum2TM");

    //点击返回�
    $(".btnGoBack1TM").on("tap",function(){
        window.location.href="../html/query.html";
    });
    $(".btnGoBack2TM").on("tap",function(){
        window.location.href="../html/query.html";
    });
    //按定票日期查询
    fun_by_time()
    function fun_by_time(){

        $(".btnQuery1TM").on("click",function(){
            var Qey_by_info={
                go_time:getRightDate("myYear1","myMonth1","myDay1"),
                over_time:getRightDate("myYear2","myMonth2","myDay2"),
                head_word:$(".iptCheCi1TM").val(),
                your_name:$(".iptPassengerName1TM").val(),
                your_id:$(".iptNum1TM").val()
            }
            $.ajax({
                type:"post",
                url:"/ajaxByInfoTM1",
                data:Qey_by_info,
                success:function(by_info){
                    var by_time_num=parseInt(by_info[0].by_time.slice(0,4)+
                        by_info[0].by_time.slice(5,7)+by_info[0].by_time.slice(8,10));//购买日期转化成的数字
                    var go_time_num=parseInt(Qey_by_info.go_time.slice(0,4)+
                        Qey_by_info.go_time.slice(5,7)+Qey_by_info.go_time.slice(8,10));//起始日期转化成的数字
                    var over_time_num=parseInt(Qey_by_info.over_time.slice(0,4)+
                        Qey_by_info.over_time.slice(5,7)+Qey_by_info.over_time.slice(8,10));//结束日期转化成的数字
                    if(by_time_num>=go_time_num&&by_time_num<=over_time_num){
                        $.ajax({
                            type:"post",
                            url:"/ajaxByInfoTM2",
                            data:Qey_by_info,
                            success:function(d_info){
                                console.log(d_info)
                                if(d_info[0].length!=0){
                                    sessionStorage.setItem("key", $(".iptNum1TM").val());
                                    window.location.href="../html/show1.html";
                                }
                            }
                        })
                    }
                }
            })
        })
    }
//按乘车日期查询
    fun_go_off()
    function fun_go_off(){
        $(".btnQuery2TM").on("click",function(){
            var Qey_by_info={
                go_time:getRightDate("myYear3","myMonth3","myDay3"),
                over_time:getRightDate("myYear4","myMonth4","myDay4"),
                head_word:$(".iptCheCi2TM").val(),
                your_name:$(".iptPassengerName2TM").val(),
                your_id:$(".iptNum2TM").val()
            }
            $.ajax({
                type:"post",
                url:"/ajaxByInfoTM3",
                data:Qey_by_info,
                success:function(by_info){
                    var by_time_num=parseInt(by_info[0].go_off.slice(0,4)+
                        by_info[0].go_off.slice(5,7)+by_info[0].go_off.slice(8,10));//购买日期转化成的数字
                    var go_time_num=parseInt(Qey_by_info.go_time.slice(0,4)+
                        Qey_by_info.go_time.slice(5,7)+Qey_by_info.go_time.slice(8,10));//起始日期转化成的数字
                    var over_time_num=parseInt(Qey_by_info.over_time.slice(0,4)+
                        Qey_by_info.over_time.slice(5,7)+Qey_by_info.over_time.slice(8,10));//结束日期转化成的数字
                    if(by_time_num>=go_time_num&&by_time_num<=over_time_num){
                        $.ajax({
                            type:"post",
                            url:"/ajaxByInfoTM2",
                            data:Qey_by_info,
                            success:function(d_info){
                                console.log(d_info)
                                if(d_info[0].length!=0){
                                    sessionStorage.setItem("key2", $(".iptNum2TM").val());
                                    window.location.href="../html/show2.html";
                                }
                            }
                        })
                    }
                }
            })
        })
    }



    //----------------------------------------



    function showTime(Y,M,D,y,m,d){
        var now_date=new Date();
        var year=now_date.getFullYear(),month=now_date.getMonth()+ 1,date=now_date.getDate();
        if(month<10){
            month="0"+month;
        }
        if(date<10){
            date="0"+date;
        }
        //显示当前的年份和后一年年份并且当前年份被选中
        var htmlYear="";
        var nextYear=year*1+1;
        var beforeyear=year*1-1;
        htmlYear+=' <option>'+ beforeyear+'</option>';
        htmlYear+=' <option selected>'+ year+'</option>';
        htmlYear+='<option>'+nextYear+'</option>';
        $(Y).html(htmlYear);

        //根据年份来判断该显示的月份的函数
        function showMonth(thisYear,thisMonth){
            var htmlMonth="";
            for(var i=1;i<=12;i++){
                if(i<10){
                    if((i-month*1)==0){
                        htmlMonth+='<option selected>0'+i+'</option>';
                    }else{
                        htmlMonth+='<option>0'+i+'</option>';
                    }
                }else{
                    if((i-month*1)==0){
                        htmlMonth+='<option selected>'+i+'</option>';
                    }else{
                        htmlMonth+='<option>'+i+'</option>';
                    }
                }
            }
            $(M).html(htmlMonth);
        }
        showMonth(year,month);

        //根据当前的年份和月份来判断显示该显示的天数的函数
        function showDay(thisYear,thisMonth,thisDay){
            var cond1 = thisYear % 4 == 0;  //条件1：年份必须要能被4整除
            var cond2 = thisYear % 100 != 0;  //条件2：年份不能是整百数
            var cond3 = thisYear % 400 ==0;  //条件3：年份是400的倍数
            //当条件1和条件2同时成立时，就肯定是闰年，所以条件1和条件2之间为“与”的关系。
            //如果条件1和条件2不能同时成立，但如果条件3能成立，则仍然是闰年。所以条件3与前2项为“或”的关系。
            //所以得出判断闰年的表达式：
            var cond = cond1 && cond2 || cond3;
            if(cond){
                if((thisMonth*1-2)==0){
                    var htmlDay="";
                    for(var i=1;i<=29;i++){
                        if(i<10){
                            if((i-date*1)==0){
                                htmlDay+='<option selected>0'+i+'</option>';
                            }else{
                                htmlDay+='<option>0'+i+'</option>';
                            }
                        }else{
                            if((i-date*1)==0){
                                htmlDay+='<option selected>'+i+'</option>';
                            }else{
                                htmlDay+='<option>'+i+'</option>';
                            }

                        }
                    }
                }else{
                    if(thisMonth*1==4||thisMonth*1==6||thisMonth*1==9||thisMonth*1==11){
                        var htmlDay="";
                        for(var i=1;i<=30;i++){
                            if(i<10){
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>0'+i+'</option>';
                                }else{
                                    htmlDay+='<option>0'+i+'</option>';
                                }

                            }else{
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>'+i+'</option>';
                                }else{
                                    htmlDay+='<option>'+i+'</option>';
                                }

                            }
                        }
                    }else{
                        var htmlDay="";
                        for(var i=1;i<=31;i++){
                            if(i<10){
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>0'+i+'</option>';
                                }else{
                                    htmlDay+='<option>0'+i+'</option>';
                                }

                            }else{
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>'+i+'</option>';
                                }else{
                                    htmlDay+='<option>'+i+'</option>';
                                }

                            }
                        }
                    }
                }
            }else{
                if((thisMonth*1-2)==0){
                    var htmlDay="";
                    for(var i=1;i<=28;i++){
                        if(i<10){
                            if((i-date*1)==0){
                                htmlDay+='<option selected>0'+i+'</option>';
                            }else{
                                htmlDay+='<option>0'+i+'</option>';
                            }
                        }else{
                            if((i-date*1)==0){
                                htmlDay+='<option selected>'+i+'</option>';
                            }else{
                                htmlDay+='<option>'+i+'</option>';
                            }

                        }
                    }
                }else{
                    if(thisMonth*1==4||thisMonth*1==6||thisMonth*1==9||thisMonth*1==11){
                        var htmlDay="";
                        for(var i=1;i<=30;i++){
                            if(i<10){
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>0'+i+'</option>';
                                }else{
                                    htmlDay+='<option>0'+i+'</option>';
                                }

                            }else{
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>'+i+'</option>';
                                }else{
                                    htmlDay+='<option>'+i+'</option>';
                                }

                            }
                        }
                    }else{
                        var htmlDay="";
                        for(var i=1;i<=31;i++){
                            if(i<10){
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>0'+i+'</option>';
                                }else{
                                    htmlDay+='<option>0'+i+'</option>';
                                }

                            }else{
                                if((i-date*1)==0){
                                    htmlDay+='<option selected>'+i+'</option>';
                                }else{
                                    htmlDay+='<option>'+i+'</option>';
                                }

                            }
                        }
                    }
                }
            }
            $(D).html(htmlDay);
        }
        showDay(year,month,date);

        //给年份下拉框绑定事件
        $(Y).on('change',function(){
            var myYear=document.getElementById(y);
            var index=myYear.selectedIndex;
            var yearVal=myYear.options[index].text;
            showMonth(yearVal,month);
            var myMonth=document.getElementById(m);
            var index2=myMonth.selectedIndex;
            var monthVal=myMonth.options[index2].text;
            showDay(yearVal,monthVal,date);
        });

        //给月份下拉框绑定事件
        $(M).on('change',function(){
            var myYear=document.getElementById(y);
            var index=myYear.selectedIndex;
            var yearVal=myYear.options[index].text;
            var myMonth=document.getElementById(m);
            var index2=myMonth.selectedIndex;
            var monthVal=myMonth.options[index2].text;
            showDay(yearVal,monthVal,date);
        })
    }

    showTime("#myYear1","#myMonth1","#myDay1","myYear1","myMonth1","myDay1");
    showTime("#myYear2","#myMonth2","#myDay2","myYear2","myMonth2","myDay2");
    showTime("#myYear3","#myMonth3","#myDay3","myYear3","myMonth3","myDay3");
    showTime("#myYear4","#myMonth4","#myDay4","myYear4","myMonth4","myDay4");

    //获得正确的出发日期的函数
    function getRightDate(Y,M,D){
        var myYear=document.getElementById(Y);
        var index=myYear.selectedIndex;
        var yearVal=myYear.options[index].text;
        var myMonth=document.getElementById(M);
        var index2=myMonth.selectedIndex;
        var monthVal=myMonth.options[index2].text;
        var myDay=document.getElementById(D);
        var index3=myDay.selectedIndex;
        var dayVal=myDay.options[index3].text;
        var RightDate=yearVal+"-"+monthVal+"-"+dayVal;
        return RightDate;
    }
})();
